from .page_base import BasePage
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver import ActionChains


class LogoutPage(BasePage):
    def __init__(self,driver=None):
        super(LogoutPage,self).__init__(driver)
    
    @property
    def avatar_element(self):
        # WebDriverWait(self.driver,3).until(EC.visibility_of_element_located((By.XPATH,"/html/body/div[1]/div/div/header/div")))
        return self.find_element(By.XPATH,'/html/body/div[1]/div/div/header/div')
        # return self.find_element(By.XPATH,'/html/body/div[1]/div/div/header/div')
    
    @property
    def username_label_element(self):
        # WebDriverWait(self.driver,3).until(EC.visibility_of_element_located((By.XPATH,"/html/body/div/div/div/header/div/span[1]/span")))
        return self.find_element(By.XPATH,'/html/body/div/div/div/header/div/span[1]/span')
    
    @property
    def user_avatar_element(self):
        return self.find_element(By.XPATH,"/html/body/div/div/div/header/div/div/img")
    
    @property
    def logout_button(self):
        # WebDriverWait(self.driver,3).until(EC.visibility_of_element_located((By.XPATH,"/html/body/div[2]/div/ul/li[4]/span")))
        return self.find_element(By.XPATH,"/html/body/div[2]/div/ul/li[4]/span")
    
    def logout(self):
        # self.avatar_element.click()
        ActionChains(self.driver).move_to_element(self.avatar_element).perform()
        # 登出按钮
        WebDriverWait(self.driver,3).until(EC.presence_of_element_located((By.XPATH,"/html/body/div[2]/div/ul/li[4]/span")))
        self.logout_button.click()
        





